<?php
/**
 * Defines Kodform_Attributes_Attributes class
 *
 *
 * @copyright 	Copyright (c) 2006 Boris Tomic (kodmasin.net)
 * @category 	Kodform
 * @package 	Kodform
 * @author 		Boris Tomic
 * @license 	http://boris.kodmasin.net/kodform4:license The BSD License
 *
 */

require_once 'Kodform/Attributes.php';

/**
 * this class can store element attribute values
 * 
 * using of this class is for ex.
 * <code>
 * $attr = new Kodform_Attributes_Attributes()
 * $attr->style= "width: 100%;";//set style attribute to some value
 * print $attr->width; //prints attribute value
 * print $attr->display() //prints all attributes as html attributes
 * </code> 
 * 
 * As this class is using overloading (__set and __get) methods you can set what ever
 * attribute you need to what ever value you need
 * 
 * This class is usualy used with Kodform_Attributes class. This classes
 * have similar names but vrey diferent functionality. So you can expect
 * change of this class name to more appropriate one.
 */
class Kodform_Attributes_Attributes{
	protected $attributes;
	/**
	 * just create Kodform_Attributes_Attributes with no attributes
	 */
	function __construct(){
		$this->attributes = array();
	}
	/**
	 * overloadeing set method
	 *
	 * @param string $name name of attribute
	 * @param mixed $value value of attribute
	 */
	private function __set($name, $value){
		$this->attributes[$name] = $value;
	}
	/**
	 * overloading get method
	 *
	 * @param string $name name of attribute which value you vant to get
	 * @return mixed value of attribute
	 */
	private function __get($name){
		if(array_key_exists($name, $this->atributes))
			return $this->attributes[$name];
		return "";
	}
	/**
	 * Generate string in form of HTML element attribute listing (name="value", ...)
	 *
	 * @return string formate like HTML element attribute list name="value"
	 */
	public function display(){
		$str ="";
		foreach($this->attributes as $name => $value)
			$str .= " " . $name . "=\"" . $value . "\"";
		return $str;
	}
}
